package org.admin.entity.domain;

import com.baomidou.mybatisplus.annotation.*;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;

@TableName("admin_users")
@Data
public class User {
    @Getter
    public enum GENDER {
        FEMALE(0),
        MALE(1);
        private final int value;
        GENDER(int value){
            this.value = value;
        }
    }

    @TableId(type= IdType.AUTO)
    private Integer id;

    private String username;

    private String password;

    private String nickname;

    private String picture;
    @Setter(AccessLevel.NONE)
    private Integer gender;
    @Setter(AccessLevel.NONE)
    @TableField(exist = false)
    private GENDER genderWith;
    private String email;

    @TableField("created_at")
    private Date createdAt;

    @TableField("updated_at")
    private Date updatedAt;

    @TableLogic
    @TableField("deleted_at")
    private Date deletedAt;



    public void setGender(Integer value){
        if(value != null) {
            for (GENDER item : GENDER.values()) {
                if (item.getValue() == value) {
                    genderWith = item;
                    break;
                }
            }
        }else{
            genderWith = null;
        }
        gender = value;
    }

    public void setGenderWith(GENDER value){
        if(value != null){
            gender = value.getValue();
        }else{
            gender = null;
        }
        genderWith = value;
    }
}
